$(function () {
    //检查时是否是分享出去的页面，添加悬浮按钮
    checkSharedPage();
    //是否允许邀请好友
    var invite = JSON.parse($("#is-invite").val());
    //推广员状态
    var agentUserStatus = $("#agent-user-status").val();
    getCourseList(1)

    if(invite){
        //邀请好友成为推广员
        wShareFn.Focus.init({
            ele: '#invite-friend',
            opt: '2 3 4',
            reset:true
        });
    }

    if(agentUserStatus == 3){
        //推广课程
        wShareFn.Focus.init({
            ele: '.extension',
            opt: '2 3 4',
            reset:true
        });
    }

    $('body').on('click','.course-id',function () {//查看课程详情
        window.location.href = baseloaction + '/mobile/course/info?courseId='+ $(this).parents('a').data('id');
    }).on('click','#allIncome',function () {//跳转总收益页面
        window.location.href = baseloaction + '/mobile/uc/agent/income/initAgentIncomeView';
    }).on('click','#child-agentuser',function () {//查看下级推广员列表
        window.location.href = baseloaction + '/mobile/uc/agent/initChildAgentUserView';
    }).on('click','#invite-friend',function () {
        if($(this).hasClass("disabled")){
        Zepto.alert("自主邀请好友功能管理员已关闭");
        return;
        }

        //点击邀请好友分享qq空间后的回调方法
        wShareFn.Focus.args={
            url: window.location.protocol+"//"+window.location.host+'/mobile/uc/agent/toOpenTwoAgent?shareKey='+ SHARE_KEY,
            desc: '你的好友邀请你成为推广员，成为推广员可推广课程赚取推广收益，收益可提现哦。快来加入吧',
            title: "推广越多，获益越多，快来赚收益吧",
            img: logourl,
            reset:true
        };
        wShareFn.Focus.opQQ = function () {
            var p = {
                url: window.location.protocol+"//"+window.location.host+'/mobile/uc/agent/toOpenTwoAgent?shareKey='+ SHARE_KEY,
                showcount: '1', /*是否显示分享总数,显示：'1'，不显示：'0' */
                desc: '棒！！！', /*默认分享理由(可选)*/
                summary: '你的好友邀请你成为推广员，成为推广员可推广课程赚取推广收益，收益可提现哦。快来加入吧', /*分享摘要(可选)*/
                title: '推广越多，获益越多，快来赚收益吧', /*分享标题(可选)*/
                site: '北京易知路科技有限公司', /*分享来源 如：腾讯网(可选)*/
                pics: logourl, /*分享图片的路径(可选)*/
                style: '203',
                width: 98,
                height: 22
            };
            var s = [];
            for (var i in p) {
                s.push(i + '=' + encodeURIComponent(p[i] || ''));
            }
            window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?' + s.join('&'));
        }
    }).on('click','.extension',function () {//推广课程
        if(agentUserStatus != 3){
            $.toast('您推广员身份状态异常，禁止推广');
            return;
        }
        var courseId = $(this).data('id');
        var courseName = $(this).data('name');
        var courseImg = $(this).data('img');
        var summary = $(this).data('summary');
        wShareFn.Focus.args={
            url: window.location.protocol+"//"+window.location.host+'/mobile/course/info?courseId='+ courseId + '&shareKey='+ SHARE_KEY,
            desc: '你的好友给你推荐了一门不错的课程，快打开看看吧！',
            title:'推广中心-'+ courseName,
            img: courseImg,
            reset:true
        };
        //点击邀请好友分享qq空间后的回调方法
        wShareFn.Focus.opQQ = function () {
            var p = {
                url: window.location.host+'/mobile/course/info?courseId='+ courseId + '&shareKey='+ SHARE_KEY,
                showcount: '0', /*是否显示分享总数,显示：'1'，不显示：'0' */
                desc: summary, /*默认分享理由(可选)*/
                summary: courseName, /*分享摘要(可选)*/
                title: courseName, /*分享标题(可选)*/
                pics: courseImg, /*分享图片的路径(可选)*/
                style: '203',
                width: 98,
                height: 22
            };
            var s = [];
            for (var i in p) {
                s.push(i + '=' + encodeURIComponent(p[i] || ''));
            }
            window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?' + s.join('&'));
        }
    }).on("click",".rule-description",function () {
        window.location.href = "/mobile/uc/agent/ruleDescription"
    });

    function getCourseList(pageNo) {
        var params = {"allow":2,"invite":true};
        params = JSON.stringify(params);
        loadMobilePathData({
            url: baseloaction + '/mobile/course/ajaxCourseList',
            contextId: 'course-list-box',
            pageNo: pageNo,
            pageCall: getCourseList,
            params: params,
            callback: function (pageNo) {

            }
        })
    }
})